package com.zrsx.searchmodel.service.serviceImpl;

import com.zrsx.searchmodel.common.dto.RecordDTO;
import com.zrsx.searchmodel.common.entity.Record;
import com.zrsx.searchmodel.common.result.PageResult;
import com.zrsx.searchmodel.mapper.RecordMapper;
import com.zrsx.searchmodel.service.RecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class RecordServiceImpl implements RecordService {
    @Autowired
    private RecordMapper recordMapper;

    /**
     * 查询用户守约记录
     * @param recordDTO
     * @return
     */
    @Override
    public PageResult<Record> getRecords(RecordDTO recordDTO, int pageNum, int pageSize) {
        // 计算分页偏移量
        int offset = (pageNum - 1) * pageSize;
        recordDTO.setOffset(offset);
        recordDTO.setLimit(pageSize);

        List<Record> data = recordMapper.list(recordDTO);
        long total = recordMapper.count(recordDTO);

        return new PageResult<>(total, data);
    }

    /**
     * 查询num条record数据
     * @param num
     * @return
     */
    @Override
    public List<Record> getRecordsByNum(Integer userId,int num) {
        return recordMapper.listByNum(userId,num);
    }

    @Override
    public int getRecordCountByType(Integer userId, String recordType) {
        return recordMapper.countByType(userId,recordType);
    }

}
